package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.service.impl.DamageListService;
import com.atguigu.jxc.service.impl.OverflowListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Description:
 * @Author: Gavin
 * @Date: 9/11/2023 10:43 PM
 */
@RequestMapping("/overflowListGoods")
@Api(tags = "商品报溢单")
@RestController
public class OverflowListController {

    @Autowired
    OverflowListService overflowListService;
    @ApiOperation("保存报损单")
    @PostMapping("save")
    public ServiceVO saveDamageList(HttpSession session, OverflowList overflowList,
                                    @RequestParam("overflowListGoodsStr")String overflowListGoodsStr){
        overflowListService.save(session,overflowList,overflowListGoodsStr);
        return new ServiceVO<>(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    @ApiOperation("指定时间范围内的报损单查询")
    @PostMapping("/list")
    public String queryByTimeSection(@RequestParam("sTime")String sTime,@RequestParam("eTime")String eTime){
        Map<String,Object> map = overflowListService.queryByTimeSection(sTime,eTime);
        return JSON.toJSONString(map);
    }
    @ApiOperation("查询报损单商品信息")
    @PostMapping("goodsList")
    public String queryOverflowListGoods(@RequestParam("overflowListId")Integer overflowListId){
        Map<String,Object> map = overflowListService.queryOverflowListGoods(overflowListId);
        return JSON.toJSONString(map);
    }
}
